import { createBrowserRouter } from "react-router-dom";

import App from "../App";
import { ErrorBlock } from "antd-mobile";
import { Link } from "react-router-dom";
const lazyHome = async () => {
  const { default: Home, loader } = await import("../pages/home/Index");
  return {
    element: <Home></Home>,
    loader,
  };
};

let routes = createBrowserRouter([
  {
    path: "/",
    element: <App />,
    children: [
      //索引路由
      {
        index: true,
        lazy: lazyHome,
      },
      // 子路由
      {
        path: "home",
        lazy: lazyHome,
      },
      {
        path: "order",
        lazy: async () => {
          const { default: Order } = await import("../pages/order/Index");
          return {
            element: <Order />,
          };
        },
      },
      {
        path: "message",
        lazy: async () => {
          const { default: Message } = await import("../pages/message/Index");
          return {
            element: <Message />,
          };
        },
      },
      {
        path: "my",
        lazy: async () => {
          const { default: My } = await import("../pages/my/Index");
          return {
            element: <My />,
          };
        },
      },
    ],
  },

  {
    path: "/login",
    lazy: async () => {
      const { default: Login } = await import("../pages/login/Index");
      return {
        element: <Login></Login>,
      };
    },
  },
  {
    path: "/reg",
    lazy: async () => {
      const { default: Reg } = await import("../pages/reg/Index");
      return {
        element: <Reg></Reg>,
      };
    },
  },
  {
    path: "/city/:type",
    lazy: async () => {
      const { default: City, loader } = await import("../pages/city/Index");
      return {
        element: <City></City>,
        loader,
      };
    },
  },
  {
    path: "/chepiao",
    lazy: async () => {
      const { default: Chepiao, loader } = await import(
        "../pages/chepiao/Index"
      );
      return {
        element: <Chepiao />,
        loader,
      };
    },
  },
  {
    path: "*",
    element: (
      <ErrorBlock fullPage description={<Link to={"/home"}>去首页</Link>} />
    ),
  },
]);
export default routes;
